
import { tags, request, summary, description, prefix, query } from 'koa-swagger-decorator'

const tag = tags(['文件上传'])

@prefix("/upload")
export default class UploadController {

  @request("post", "/upload")
  @summary("上传文件")
  @description("上传文件")
  @tag
  async upload (ctx) {
    const file = ctx.request.files.file;

    const fileTyps = ['image/jpeg', 'image/png']

    if (fileTyps.includes(file.mimetype)) {
      if (file) {
        let res = {
          path: file.newFilename
        }
        ctx.success(res)
      }
      else {
        ctx.fail(400, '上传失败')
      }
    }
    else {
      ctx.fail(400, '不支持该文件格式')
    }



  }
}
